﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ClaseBase;
using System.Collections.ObjectModel;

namespace Grupo04Playa
{
    /// <summary>
    /// Interaction logic for Logincontrol.xaml
    /// </summary>
    public partial class Logincontrol : UserControl
    {
        public Logincontrol()
        {
            InitializeComponent();

            textBox1.Focus();


        }
       

        private void button1_Click(object sender, RoutedEventArgs e)
        {

            Window.GetWindow(this).Close();

        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {





            //if ((textBox1.Text == "antonio") && (passwordBox1.Password.Equals("1234") && tipoUsuario(comboBox1.SelectionBoxItem.ToString()) == true))
            if (validar(textBox1.Text, passwordBox1.Password) == true && tipoUsuario(comboBox1.SelectionBoxItem.ToString()) == true)
            {

                
                MainWindow principal = new MainWindow(textBox1.Text, comboBox1.SelectionBoxItem.ToString());

                principal.Show();

                Window.GetWindow(this).Close();
                

            }
            else if (textBox1.Text == "")
            {
                MessageBox.Show("ingrese usuario");
            }
            else if (passwordBox1.Password == "")
            {
                MessageBox.Show("ingrese contraseña");
            }
            else if (comboBox1.SelectionBoxItem.ToString() == "")
            {
                MessageBox.Show("ingrese tipo");
            }
            else
            {

                MessageBox.Show("Usuario o contraseña Incorrectos.");

            }






        }

        private bool tipoUsuario(String usuario)
        {
            bool bandera = true;


            if (usuario.Equals(""))
            {


                bandera = false;
            }


            return bandera;
        }

        public System.Threading.Thread NuevoHilo { get; set; }

        private void passwordBox1_KeyDown(object sender, KeyEventArgs e)
        {



          
        }


        public bool validar(string nom, string password) {
            bool bandera = false;
            TrabajarUsuario j = new TrabajarUsuario();


      
        foreach(Usuario usu in  j.TraerColeccionDeUsuario()){


            if (usu.UserName.Equals(nom) && usu.Password.Equals(password)) {


                bandera = true;
                
            
            }
            
        
        }


        return bandera;

        
        
        }



    }
}
